﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DAL = AccessDAL;
using CommonFunc;
using DBUtility;

public partial class Manageweb_ManageNews_NewsRecycle : System.Web.UI.Page
{
    DAL.NewsClassTableAdapters.NewsClassTableAdapter DNC =
        new DAL.NewsClassTableAdapters.NewsClassTableAdapter();

    MODEL.News MN = new MODEL.News();
    MODEL.News _MN = new MODEL.News();
    MODEL.ProductClass MPC = new MODEL.ProductClass();
    MODEL.ProductClass _MPC = new MODEL.ProductClass();

    BLL.News BN = new BLL.News();
    BLL.ProductClass BPC = new BLL.ProductClass();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Cookies["MasterID"] == null)
        {
            Response.Redirect("../Default.aspx");
        }
    }


    #region 类别标题 [格式化]
    protected string FormatClassTitle(object _Title, object _Level)
    {
        return ClassCode.CreateClassListItemText(_Title.ToString(), _Level.ToString());
    }
    #endregion


    #region 修改按钮 [GridView] [Command]
    protected void LBtn_Mod_Command(object sender, CommandEventArgs e)
    {
        try
        {
            Response.Redirect("AddNews.aspx?NewsID=" + e.CommandArgument.ToString());
        }
        catch (Exception ex)
        {
            LB_NewsRecycle.Text = ex.Message;
        }
    }
    #endregion


    #region 恢复按钮 [GridView] [Command]
    protected void LBtn_RollBack_Command(object sender, CommandEventArgs e)
    {
        try
        {
            MN.News_ID = Convert.ToInt32(e.CommandArgument);

            BN.MarkIsDel(MN);

            GV_DelNewsList.DataBind();

            LB_NewsRecycle.Text = "恢复成功";
        }
        catch (Exception ex)
        {
            LB_NewsRecycle.Text = ex.Message;
        }
    }
    #endregion


    #region 确认删除按钮 [GridView] [Command]
    protected void LBtn_RealDel_Command(object sender, CommandEventArgs e)
    {
        try
        {
            MN.News_ID = Convert.ToInt32(e.CommandArgument);

            BN.Del(MN);

            GV_DelNewsList.DataBind();

            LB_NewsRecycle.Text = "删除成功";
        }
        catch (Exception ex)
        {
            LB_NewsRecycle.Text = ex.Message;
        }
    }
    #endregion


    #region 搜索按钮 [Click]
    protected void Btn_Search_Class_Click(object sender, EventArgs e)
    {
        try
        {
            string SQLstr_Search = "SELECT * FROM ([News] INNER JOIN [NewsClass] ";
            
            SQLstr_Search += " ON News.News_ClassID = NewsClass.NC_ID) ";
            
            SQLstr_Search += " WHERE [News_IsDel]=true ";

            SQLstr_Search += " AND [News_Title] LIKE '%" + TB_Search.Text + "%' ";

            SQLstr_Search += " ORDER BY [News_DateTime] DESC";

            DataTable DT_Search = AccHelper.GetDataTable(SQLstr_Search);

            GV_DelNewsList.DataSourceID = "";

            GV_DelNewsList.DataSource = DT_Search.DefaultView;

            GV_DelNewsList.DataBind();
        }
        catch (Exception ex)
        {
            LB_NewsRecycle.Text = ex.Message;
        }
    }
    #endregion
}
